﻿using System;
using System.Collections.Generic;
using System.Text;
using Scripting;

namespace UserScripts
{
    class StepEval : ScriptBase
    {
        public int Main(int number)
        {
            int[] stepinfo = GetStepInfo(number);
            int roll = EvalStep(stepinfo, number);
            return roll;
        }
        public int GetRoll(int number)
        {
            int[] stepinfo = GetStepInfo(number);
            int roll = EvalStep(stepinfo, number);
            return roll;
        }
        static int[] GetStepInfo(int number)
        {
            switch (number)
            {
                case 1:
                    {
                        int[] info = { 6 };
                        return info;
                    }
                case 2:
                    {
                        int[] info = { 6 };
                        return info;
                    }
                case 3:
                    {
                        int[] info = { 6 };
                        return info;
                    }
                case 4:
                    {
                        int[] info = { 6 };
                        return info;
                    }
                case 5:
                    {
                        int[] info = { 8 };
                        return info;
                    }
                case 6:
                    {
                        int[] info = { 10 };
                        return info;
                    }
                case 7:
                    {
                        int[] info = { 12 };
                        return info;
                    }
                case 8:
                    {
                        int[] info = { 6, 6 };
                        return info;
                    }
                case 9:
                    {
                        int[] info = { 8, 6 };
                        return info;
                    }
                case 10:
                    {
                        int[] info = { 8, 8 };
                        return info;
                    }
                case 11:
                    {
                        int[] info = { 10, 8 };
                        return info;
                    }
                case 12:
                    {
                        int[] info = { 10, 10 };
                        return info;
                    }
                case 13:
                    {
                        int[] info = { 12, 10 };
                        return info;
                    }
                case 14:
                    {
                        int[] info = { 12, 12 };
                        return info;
                    }
                case 15:
                    {
                        int[] info = { 12, 6, 6 };
                        return info;
                    }
                case 16:
                    {
                        int[] info = { 12, 8, 6 };
                        return info;
                    }
                case 17:
                    {
                        int[] info = { 12, 8, 8 };
                        return info;
                    }
                case 18:
                    {
                        int[] info = { 12, 10, 8 };
                        return info;
                    }
                case 19:
                    {
                        int[] info = { 12, 10, 10 };
                        return info;
                    }
                case 20:
                    {
                        int[] info = { 12, 12, 10 };
                        return info;
                    }
                case 21:
                    {
                        int[] info = { 12, 12, 12 };
                        return info;
                    }
                case 22:
                    {
                        int[] info = { 12, 12, 6, 6 };
                        return info;
                    }
                case 23:
                    {
                        int[] info = { 12, 12, 8, 6 };
                        return info;
                    }
                case 24:
                    {
                        int[] info = { 12, 12, 8, 8 };
                        return info;
                    }
                case 25:
                    {
                        int[] info = { 12, 12, 10, 8 };
                        return info;
                    }
                case 26:
                    {
                        int[] info = { 12, 12, 10, 10 };
                        return info;
                    }
                case 27:
                    {
                        int[] info = { 12, 12, 12, 10 };
                        return info;
                    }
                case 28:
                    {
                        int[] info = { 12, 12, 12, 12 };
                        return info;
                    }
                case 29:
                    {
                        int[] info = { 12, 12, 12, 6, 6 };
                        return info;
                    }
                case 30:
                    {
                        int[] info = { 12, 12, 12, 8, 6 };
                        return info;
                    }
                case 31:
                    {
                        int[] info = { 12, 12, 12, 8, 8 };
                        return info;
                    }
                case 32:
                    {
                        int[] info = { 12, 12, 12, 10, 8 };
                        return info;
                    }
                case 33:
                    {
                        int[] info = { 12, 12, 12, 10, 10 };
                        return info;
                    }
                case 34:
                    {
                        int[] info = { 12, 12, 12, 12, 10 };
                        return info;
                    }
                case 35:
                    {
                        int[] info = { 12, 12, 12, 12, 12 };
                        return info;
                    }
                case 36:
                    {
                        int[] info = { 12, 12, 12, 12, 6, 6 };
                        return info;
                    }
                case 37:
                    {
                        int[] info = { 12, 12, 12, 12, 8, 6 };
                        return info;
                    }
                case 38:
                    {
                        int[] info = { 12, 12, 12, 12, 8, 8 };
                        return info;
                    }
                case 39:
                    {
                        int[] info = { 12, 12, 12, 12, 10, 8 };
                        return info;
                    }
                case 40:
                    {
                        int[] info = { 12, 12, 12, 12, 10, 10 };
                        return info;
                    }
                default:
                    {
                        int die = Convert.ToInt32(1.6825 * number / 6);
                        int[] info = { die, die, die, die, die, die };
                        return info;
                    }
            }
        }
        static int EvalStep(int[] array, int number)
        {
            int roll = 0;
            int nroll;
            int xroll;
            foreach (int i in array)
            {
                do
                {
                    Random random = new Random();
                    nroll = random.Next(1, i + 1);
                    xroll = nroll;
                    if (number == 1) nroll = nroll - 3;
                    else if (number == 2) nroll = nroll - 2;
                    else if (number == 3) nroll = nroll - 1;
                    if (nroll < 1) nroll = 1;
                    roll = roll + nroll;
                    System.Threading.Thread.Sleep(10);
                }
                while (xroll == i);
            }
            return roll;
        }

    }
}
